package cn.jiadakeji.parent.config;
import cn.jiadakeji.parent.common.util.SecurityUtils;
import cn.jiadakeji.parent.dto.CustomerJwtDTO;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author hhaoyu
 * 自动填充枚举
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        CustomerJwtDTO loginUser = SecurityUtils.getLoginUser();
        this.strictInsertFill(metaObject, "delFlag", String.class, "0");
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictUpdateFill(metaObject,"updateTime", Date.class, new Date());
        this.strictInsertFill(metaObject,"createBy",String.class,loginUser.getId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        CustomerJwtDTO loginUser = SecurityUtils.getLoginUser();
        this.strictUpdateFill(metaObject,"updateTime", Date.class, new Date());
        this.strictUpdateFill(metaObject,"updateBy", String.class,loginUser.getId());
    }
}
